Skip to content

Time\Duration - #23073

Open
TimWolla wants to merge 3 commits into
php:masterfrom
TimWolla:time-duration
Open

Time\Duration#23073
TimWolla wants to merge 3 commits into
php:masterfrom
TimWolla:time-duration

Conversation

@TimWolla

@TimWolla TimWolla commented Aug 5, 2026

Copy link
Copy Markdown
Member

Comment thread ext/date/config0.m4 Outdated
Comment thread ext/date/time_duration.c
Comment thread ext/date/php_date_time_duration.c Outdated
Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/php_date_time_duration.c Outdated
Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/tests/time/duration/fromNanoseconds_64.phpt Outdated
Comment thread ext/date/php_date_time_duration.c Outdated
Comment thread ext/date/time_duration.c
Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/php_date_time_duration.c Outdated

php_date_time_duration *original = Z_DATE_TIME_DURATION_P(ZEND_THIS);
php_date_time_duration *additional = php_date_time_duration_from_obj(duration);
php_date_time_duration *new = Z_DATE_TIME_DURATION_P(return_value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When either original or additional has recount==1, it may be possible to reuse it?

Comment thread ext/date/time_duration.c Outdated
@TimWolla
TimWolla force-pushed the time-duration branch 8 times, most recently from ebb8107 to 5f203d8 Compare August 5, 2026 20:09
@TimWolla TimWolla added the RFC label Aug 5, 2026
@TimWolla
TimWolla requested review from arnaud-lb and derickr August 5, 2026 20:16
@TimWolla
TimWolla force-pushed the time-duration branch 2 times, most recently from 89e45ab to 6390166 Compare August 5, 2026 20:43
Comment thread ext/date/tests/time/duration/methods/add.phpt Outdated
Comment thread ext/date/tests/time/duration/methods/div.phpt Outdated
Comment thread ext/date/tests/time/duration/methods/mul.phpt Outdated
Comment thread ext/date/php_time.c
Comment thread ext/date/php_time.c Outdated
Comment thread ext/date/php_time.h Outdated
Comment thread ext/date/php_time.h Outdated
@TimWolla
TimWolla force-pushed the time-duration branch 2 times, most recently from 95eee76 to a2a58e7 Compare August 6, 2026 08:23
Comment thread ext/date/tests/time/duration/methods/fromIso8601DurationString.phpt Outdated
Comment thread ext/date/lib/duration.c
Comment thread ext/date/php_date.h Outdated
Comment thread ext/date/php_time.h
Comment thread ext/date/time_duration.c
Comment thread ext/date/time_duration.c
Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/time_duration.c
@TimWolla
TimWolla marked this pull request as ready for review August 6, 2026 14:39
TimWolla and others added 3 commits August 6, 2026 18:02
…om*()`

This is useful for patterns like the following:

    for (;;) {
        $watchers = $poll->wait(Time\Duration::fromSeconds(1));
        // …
    }

which is repeatedly creating identical duration objects for every loop
iteration.

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me otherwise

Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/time_duration.c
Comment on lines +98 to +100
ZVAL_LONG(OBJ_PROP_NUM(&object->std, 0), object->duration.seconds);
ZVAL_LONG(OBJ_PROP_NUM(&object->std, 1), object->duration.nanoseconds);
ZVAL_BOOL(OBJ_PROP_NUM(&object->std, 2), object->duration.negative);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably harmless, but we should reset prop flags here with Z_PROP_FLAG_P(variable_ptr) &= ~(IS_PROP_UNINIT|IS_PROP_REINITABLE);

Comment thread ext/date/time_duration.c Outdated
/* This constraint is an explicit part of PHP's API. While it is currently also
* enforced by timelib, this might change in a future version of timelib, thus
* we also enforce it manually. */
|| object->duration.seconds > ((timelib_ull)UINT64_C(9223372035))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment about how this constraint was chosen? It's documented in the RFC but not in the code, I believe

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense and will be done with the next push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants